package priv.bruce.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import priv.bruce.service.SelectCommentsByUsernameService;

public class FindCommentsInfoByUsernameServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private SelectCommentsByUsernameService byUsernameServic = new SelectCommentsByUsernameService();

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		String username = request.getParameter("username");
		try {
			Map<String, Object> comments = byUsernameServic.findCommentByUsername(username);
			response.getWriter().append(JSON.toJSONString(comments));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		String username = request.getParameter("username");
		try {
			Map<String, Object> comments = byUsernameServic.findCommentByUsername(username);
			response.getWriter().append(JSON.toJSONString(comments));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
